<div class="filter">
    <?php if(isset($displayCols[7])): ?>
    <select class="filters_col" id="share_sites" name="sites" >
        <option value="">---Sites---</option>
        <?php foreach($filters['site'] as $site): ?>
            <option value="<?php echo $site; ?>"><?php echo $site; ?></option>
        <?php endforeach; ?>
    </select>
    <?php endif; ?>
    <input type="button" id="share_filter" value=">>>Filter" />
</div>

<table class="tablesorter" id="tab1" >
    <thead>
        <tr>
            <th class="col_date">Date<span class="close">X</span></th>
            <?php if(isset($displayCols[7])):?> <th class="col_site">Site<span class="close">X</span></th> <?php endif;?>
            <th class="col_emailru">Email Refer Uses<span class="close">X</span></th>
            <th class="col_emailr#">Email Refer #<span class="close">X</span></th>
            <th class="col_emailsent">Email Sent<span class="close">X</span></th>
            <th class="col_emailopened">Email Opened<span class="close">X</span></th>
            <th class="col_emailclicks">Clicks<span class="close">X</span></th>
            <th class="col_emailshortleads">Short Leads<span class="close">X</span></th>
            <th class="col_fbru">Facebook Refer Uses<span class="close">X</span></th>
            <th class="col_fbfs">Facebook Friends Shared<span class="close">X</span></th>
            <th class="col_fbclicks">Clicks<span class="close">X</span></th>
            <th class="col_fbshortleads">Short Leads<span class="close">X</span></th>
            <th class="col_twitterru">Twitter Refer Uses<span class="close">X</span></th>
            <th class="col_twitterfollowers">Total Followers<span class="close">X</span></th>
            <th class="col_twitterclicks">Clicks<span class="close">X</span></th>
            <th class="col_twittershortleads">Short Leads<span class="close">X</span></th>
        </tr>
    </thead>
    <tbody>
    	<?php
            if((!empty($reportItems)) && $reporttype=="4"):
                $durations = Util::getReportDuration($duration);
                foreach ($reportItems as $k=>$reportItem):
					list($date['start'], $site) = explode('|', $k);
					if($site == '' && isset($displayCols[7])){ continue; }
					if($interval == 2){
						list($year, $week) = str_split($date['start'], 4);
						$date = Util::getStartAndEndDate($week, $year);
					}
		?>
                <tr>
					<td class="col_date"><?php echo $date['start'];?> <?php if($interval==2){ echo '---'.$date['end'];} ?></td>
		            <?php if(isset($displayCols[7])): ?> <td class="col_site"><?php echo strtolower($site);?></td> <?php endif; ?>
		            <td class="col_emailru"><?php echo isset($reportItem['ref_email'])? $reportItem['ref_email'] : 0;  ?></td>
		            <td class="col_emailr#"><?php echo isset($reportItem['share_email'])? $reportItem['share_email'] : 0;  ?></td>
		            <td class="col_emailsent"><?php echo isset($reportItem['ref_email_sent'])? $reportItem['ref_email_sent'] : 0;  ?></td>
		            <td class="col_emailopened"><?php echo isset($reportItem['ref_email_open'])? $reportItem['ref_email_open'] : 0;  ?></td>
		            <td class="col_emailclicks"><?php echo isset($reportItem['em_landing'])? $reportItem['em_landing'] : 0;  ?></td>
		            <td class="col_emailshortleads"><?php echo isset($reportItem['em_basic_reg'])? $reportItem['em_basic_reg'] : 0;  ?></td>
		            <td class="col_fbru"><?php echo isset($reportItem['ref_facebook'])? $reportItem['ref_facebook'] : 0;  ?></td>
		            <td class="col_fbfs"><?php echo isset($reportItem['share_facebook'])? $reportItem['share_facebook'] : 0;  ?></td>
		            <td class="col_fbclicks"><?php echo isset($reportItem['fb_landing'])? $reportItem['fb_landing'] : 0;  ?></td>
		            <td class="col_fbshortleads"><?php echo isset($reportItem['fb_basic_reg'])? $reportItem['fb_basic_reg'] : 0;  ?></td>
		            <td class="col_twitterru"><?php echo isset($reportItem['ref_twitter'])? $reportItem['ref_twitter'] : 0;  ?></td>
		            <td class="col_twitterfollowers"><?php echo isset($reportItem['share_twitter'])? $reportItem['share_twitter'] : 0;  ?></td>
		            <td class="col_twitterclicks"><?php echo isset($reportItem['tw_landing'])? $reportItem['tw_landing'] : 0;  ?></td>
		            <td class="col_twittershortleads"><?php echo isset($reportItem['tw_basic_reg'])? $reportItem['tw_basic_reg'] : 0;  ?></td>
                </tr>
            <?php endforeach;?>
        <?php endif;?>
    </tbody>
</table>

<script type="text/javascript" src="<?php echo JS_DIR; ?>jquery.tablesorter.js"></script>
<script type="text/javascript" src="<?php echo JS_DIR; ?>jquery.uitablefilter.js"></script>
<script type="text/javascript">
	var $table = $('#tab1');
	$table.tablesorter({sortList: [[0,0]]});

	$('#share_filter').click(function(){
		var id_to_header={
						  "share_sites":"Site"
					   	 };
		
		var $table = $('#tab1');
		var filters = new Array();
	    var elems = $('.filters_col');
	    elems.each(function(){
			var elem = $(this);
			if(elem.css('display') != 'none'){
				if(elem.val() != ""){
					filters[elem.val()] = id_to_header[elem.attr('id')];
				}
			}
		});
		console.log(filters);
	    $.uiTableFilter( $table, filters);
	});
	
</script>
